
Uec3.ShowPurchaseOrderWindowCreator = Ext.extend(Ext.app.Module, {
   id: 'showPurchaseOrderWindowCreator',
   type: 'common/notepad',
   iarea: null,

   /**
    * Initialize this module.
    * This function is called at startup (page load/refresh).
    */
   init : function(initParams){
   		
   },
	
	/**
	 * Create this modules window here.
	 */
   createWindow : function(){
      var desktop = this.app.getDesktop();
      var win = desktop.getWindow('showPurchase');
      if(win) {
      	win.toFront();
      } else {
      	
      	 var versionCode = ++(PurchaseCount.count);
      	 var viewPanel = this.getPanel();
      	 
         win = desktop.createWindow({
            id: 'showPurchase',
            title: '浏览采购订单概要',
            width: 1010,
            height: 500,
            iconCls: 'acc-icon',
            animCollapse:true,
            constrainHeader: true,
            maximizable: true,
            taskbuttonTooltip: "浏览采购订单概要",
            layout: "fit",
//            tools: [
//               {
//                  id: 'refresh',
//                  handler: Ext.emptyFn,
//                  scope: this
//               }
//             ],
             items:[ viewPanel ]
         });
         viewPanel.main_win = win;
		 win.versionCode = versionCode;
      	 win.show();
      }
   },
   
   /**
	* 打开行记录
	*/
	toUpdatePur : function(id) {
		var record = this.show_pur_list_store.getById(id);
		var desktop = Uec3.App.getDesktop(); 
		if(record.data.workFlowId + '' == '2') {
			desktop.launchWindowByParam("addAutoPurchaseOrderWindowCreator",{id : record.data.id, 
//														init_status : record.data.status,
														init_buyerCode : record.data.codeOfBuyer
														});
		} else if(record.data.workFlowId + '' == '1') {
			desktop.launchWindowByParam("addOutPurchaseOrderWindowCreator",{id : record.data.id, 
//														init_status : record.data.status,
														init_buyerCode : record.data.codeOfBuyer
														});
		}
	},
		
   getPanel : function() {
	
		var SHOW_PUR_LIST_GRID_ID = 'show_pur_list_grid_id';
		var PUR_BUTTON_FDSET_ID = 'purButnFdset';
		var PUR_BTN_FDSET_ID = 'btnSetId';
		
		
		function createPurDetail() {
			
			var p = join_panel.get('detail_panel_id');
			if(p) {
				p.destroy();
				p = null;
			}
		
		}
		
		// 来源下拉框
		var sourceType_store = getDictionaryStore(RES_PATH, {
			group : 'part_source'
		});
		var source_cmb = getDictionaryComboBox(sourceType_store, 'local', 'part_source',
				'来源', 'source');
		sourceType_store.load();
		
		
		var show_pur_list_record = Ext.data.Record.create( [
			{
				name : 'id'
			}, {
				name : 'codeOfBuyer'
			}, {
				name : 'sellerName'
			}, {
				name : 'status'
			}, {
				name : 'statusDes'
			}, {
				name : 'amount'
			}, {
				name : 'currentor'
			}, {
				name : 'creator'
			}, {
				name : 'gmtCreate'
			}, {
				name : 'submitter'
			}, {
				name : 'gmtSubmit'
			}, {
				name : 'deliveryer'
			}, {
				name : 'gmtDelivery'
			}, {
				name : 'receiverName'
			}, {
				name : 'gmtAccept'
			}, {
				name : 'memoOfBuyer'
			}, {
				name : 'partnerNameByBuyer'
			}, {
				name : 'workFlowId'
			}
		] );
			
		/**
		 * 删除行记录
		 */
		function toDelPur(record) {
			Ext.Ajax.request( {
				url : RES_PATH + "/purchase/deleteOnlinePurAndDetails.do",
				params : {
					'orderId' : record.id
				},
				success : function(data) {
					Ext.Msg.alert('提示信息', '数据删除成功...');
	
	//				show_pur_list_store.remove(record);
	//				show_pur_list_grid.getView().refresh();
	//				alert(show_pur_list_grid.getBottomToolbar().cursor);
					var total = show_pur_list_grid.getBottomToolbar().getPageData().total;
					var start = show_pur_list_grid.getBottomToolbar().cursor;
					if(start == total - 1) {
						start -= 2;
					}
					var obj = {params : {start : start}};
					
					show_pur_list_store.load(obj);
					
					
					
				}
			} );
		}
		
		
		
		var show_details_record = Ext.data.Record.create( [ 
			{
				name : 'id'
			},{
				name : 'code'
			}, {
				name : 'name'
			}, {
				name : 'source'
			}, {
				name : 'measurementUnit'
			}, {
				name : 'brand'
			}, {
				name : 'origin'
			}, {
				name : 'price'
			}, {
				name : 'price'
			}, {
				name : 'orderQuantity'
			}, {
				name : 'level1Id'
			}, {
				name : 'partId'
			}, {
				name : 'level1Name'
			}, {
				name : 'level2Name'
			} 
		]);
	
	
		
		var show_details_store = new Ext.data.JsonStore( {
			url : PUR_DETAILS_QUERY_URL,
			baseParams : {
				orderId : this.orderId
			},
			mode : "local",
			totalProperty : "results",
			root : "purchaseDetails",
			idProperty : "id",
			pruneModifiedRecords : true,
			fields : show_details_record
		});
		
		var show_details_colName = new Ext.grid.ColumnModel( [ new Ext.grid.RowNumberer(),
			{
				header : '零件编码',
				dataIndex : 'code'
			}, {
				header : '零件名称',
				dataIndex : 'name'
			}, {
				header : '来源',
				dataIndex : 'source',
				render : getSourceName,
				editor : source_cmb
			}, {
				header : '单位',
				dataIndex : 'measurementUnit'
			}, {
				header : '品牌',
				dataIndex : 'brand',
				sortable : true
			}, {
				header : '产地',
				dataIndex : 'origin',
				sortable : true
			}, {
				header : '媒体价',
				dataIndex : 'price'
			}, {
				header : '订购价',
				dataIndex : 'price'
			}, {
				header : '订购数量',
				dataIndex : 'orderQuantity'
			}
		]);
	
		var show_details_grid = new Ext.grid.EditorGridPanel( {
			title : '采购订单明细',
			height : 200,
			clicksToEdit : 1,
			colModel : show_details_colName,
			autoScroll : true,
			store : show_details_store
		});
		
		
			
		var purchase_sale_id_hidden = new Ext.form.Hidden( {
			name : 'sellerId'
		});
		
		var purchase_areaId_hidden = new Ext.form.Hidden( {
			name : 'areaId'
		});
		
		var purchase_id_hidden = new Ext.form.Hidden( {
			name : 'id'
		});
	
	
		// 区县下拉框
		var dist_cmb = getDistrictCombox(RES_PATH);// dist_cmb.setWidth(80);
		dist_cmb.hiddenName = null;
		dist_cmb.name = 'district';
		// 城市下拉框
		var city_cmb = getCityCombox(RES_PATH, dist_cmb);
		city_cmb.hiddenName = null;
		city_cmb.name = 'city';
		// 省份下拉框
		var prov_cmb = getProvinceCombox(RES_PATH, city_cmb, dist_cmb);
		prov_cmb.hiddenName = null;
		prov_cmb.name = 'province';
		
		
		// 支付方式下拉框
		var payType_store = getDictionaryStore(RES_PATH, {
			group : 'payType'
		});
		var payType_cmb = getDictionaryComboBox(payType_store, 'local', 'paymentType',
				'支付方式', null);
		
				
		// 运输方式下拉框
		var transportType_store = getDictionaryStore(RES_PATH, {
			group : 'transportType'
		});
		var transportType_cmb = getDictionaryComboBox(transportType_store, 'local',
				'transportType', '运输方式', null);
	
		
		// 采购订单主表头信息
		var show_pur_form = {
	//		xtype : 'panel',
			title : '采购订单',
			layout : 'column',
			width : '100%',
			items : [ {
				columnWidth : .2,
				layout : 'form',editable:false,
				items : [ {
					xtype : 'textfield',
					fieldLabel : '供应商',
					name : 'sellerName',
					anchor : '100%'
				} ]
			}, purchase_id_hidden, purchase_sale_id_hidden, purchase_areaId_hidden, {
				columnWidth : .2,
				layout : 'form',
				items : [ payType_cmb ]
			}, {
				columnWidth : .2,
				layout : 'form',
				items : [ transportType_cmb ]
			}, {
				columnWidth : .26,
				layout : 'form',editable:false,
				items : [ {
					xtype : 'textarea',
					fieldLabel : '备注',
					name : 'memoOfBuyer',
					anchor : '100%'
				} ]
			}, {
				columnWidth : .2,
				layout : 'form',editable:false,
				items : [ {
					xtype : 'textfield',
					fieldLabel : '退货地址',
					name : 'street',
					anchor : '100%'
				} ]
			}, {
				columnWidth : .2,
				layout : 'form',
				items : [ prov_cmb ]
			}, {
				columnWidth : .2,
				layout : 'form',
				items : [ city_cmb ]
			}, {
				columnWidth : .2,
				layout : 'form',
				items : [ dist_cmb ]
			}, {
				columnWidth : .2,
				layout : 'form',editable:false,
				items : [ {
					xtype : 'textfield',
					fieldLabel : '联系人',
					name : 'receiverName',
					anchor : '100%'
				} ]
			}, {
				columnWidth : .2,
				layout : 'form',editable:false,
				items : [ {
					xtype : 'textfield',
					fieldLabel : '邮编',
					name : 'postCode',
					anchor : '100%'
				} ]
			}, {
				columnWidth : .2,
				layout : 'form',editable:false,
				items : [ {
					xtype : 'textfield',
					fieldLabel : '电话',
					name : 'phone',
					anchor : '100%'
				} ]
			}, {
				columnWidth : .2,
				layout : 'form',editable:false,
				items : [ {
					xtype : 'textfield',
					fieldLabel : '手机',
					name : 'mobile',
					anchor : '100%'
				} ]
			} ]
		};
		
		var pur_formReader = new Ext.data.JsonReader(
			{
				
				root : ""
		//		totalProperty : 'totalProperty'
			},
			
			[
				{name : 'sellerName'},
				{name : 'memoOfBuyer'},
				{name : 'street'},
				{name : 'receiverName'},
				{name : 'postCode'},
				{name : 'phone'},
				{name : 'mobile'},
				{name : 'province'},
				{name : 'city'},
				{name : 'district'},
				{name : 'paymentType'},
				{name : 'transportType'},
				{name : 'partnerNameByBuyer'},
				{name : 'partnerIdByBuyer'},
				{name : 'pyCode'}
			]
		)
	
		var show_pur_panel = new Ext.form.FormPanel({
	
	//		labelAlign : 'right',
	//		frame : true,
			height : 180,
	//		title : '采购订单',
	//		layout : 'column',
	//		labelWidth : 40,
			baseCls : "x-plain",
			reader : pur_formReader,
			defaults : {  editable:false,
				width : 180
			},
			items : [show_pur_form]
		});
		
	
		
		var show_details_panel = new Ext.Panel({
			id : 'detail_panel_id',
	//		labelAlign : 'right',
	//		frame : true,
			height : 400,
			autoWidth : true,
			autoScroll : true,
			items : [show_pur_panel, show_details_grid]
		});
	
			
		
		function initPurBtnsMess() {
			Ext.Ajax.request( {
				url : PUR_INITIAL_BUTNS_URL,
				params : {status : this.status},
				success : function(data) {
					var vo = Ext.decode(data.responseText);
					
					var btn_fdset = new Ext.form.FieldSet({
						border : false,
						id : PUR_BUTTON_FDSET_ID,
						layout : 'column',
						columnWidth : .7,
						width : '100%',
						items : []
					});
					
					createNewPurButtons(btn_fdset, vo.btns, PUR_BUTTON_FDSET_ID);
					this.show_details_panel.add(btn_fdset);
					
					this.show_details_panel.doLayout(true);
				}.bind(this)
			} );
		}
			
		function purNewCreate() {
			window.location.href = PUR_NEW_CREATE_URL; 
		}
		
		function showPurDetail(orderId, status) {
			var tmp = {};
			tmp.orderId = orderId;
			tmp.status = status;
			createPurDetail.bind(tmp)();
		}
		
		var show_pur_list_form = new Ext.form.FieldSet({
	//		xtype : 'panel',
			title : '采购订单查询',
			layout : 'column',
			width : '95%',
			items : [
					{
						columnWidth : .14,
						layout : 'form',
						items : [ {
							xtype : 'textfield',
							fieldLabel : '供应商',
							name : 'sellerId',
							anchor : '100%',
							id : 'sellerId'
						} ]
					},
					{
						columnWidth : .14,
						layout : 'form',
						items : [ {
							xtype : 'textfield',
							fieldLabel : '编码',
							name : 'code',
							anchor : '100%',
							id : 'code'
						} ]
					},
					{
						columnWidth : .14,
						layout : 'form',
						items : [ {
							xtype : 'textfield',
							fieldLabel : '名称',
							name : 'partName',
							anchor : '100%',
							id : 'partName'
						} ]
					},
					{
						columnWidth : .14,
						layout : 'form',
						items : [ source_cmb ]
					},
					{
						columnWidth : .14,
						layout : 'form',
						items : [ {
							xtype : 'textfield',
							fieldLabel : '品牌',
							name : 'brand',
							anchor : '100%',
							id : 'brand'
						} ]
					},
					{
						columnWidth : .14,
						layout : 'form',
						items : [ {
							xtype : 'textfield',
							fieldLabel : '产地',
							name : 'origin',
							anchor : '100%',
							id : 'origin'
						} ]
					},
					new Ext.form.TextField( {
						columnWidth : .05,
						hidden : true
					}),
					{
						columnWidth : .14,
						layout : 'form',
						items : [ {
							xtype : 'button',
							text : '查找',
							name : 'memo',
							width : 20,
							// anchor : '100%',
							listeners : {
								click : function() {
									var sellerId = Ext.get('sellerId').getValue();
									if (sellerId.trim() != '') {
										show_pur_list_store.baseParams.sellerId = sellerId;
									}
	
									var code = Ext.get('code').getValue();
									if (code.trim() != '') {
										show_pur_list_store.baseParams.code = code;
									}
	
									var partName = Ext.get('partName').getValue();
									if (partName.trim() != '') {
										show_pur_list_store.baseParams.partName = partName;
									}
	
									var brand = Ext.get('brand').getValue();
									if (brand.trim() != '') {
										show_pur_list_store.baseParams.brand = brand;
									}
	
									var origin = Ext.get('origin').getValue();
									if (origin.trim() != '') {
										show_pur_list_store.baseParams.origin = origin;
									}
	
									var source = source_cmb.getValue() + '';
									if (source.trim() != '') {
										show_pur_list_store.baseParams.source = source;
									}
	
									var obj = {
										callback : function() {
											addUpdateDetailEvent();
										}
									};
									
									show_pur_list_store.load(obj);
									show_pur_list_store.baseParams = {};
								}
							}
						} ]
					} ]
			});
		
			
		
		var show_pur_list_colName = new Ext.grid.ColumnModel( [ new Ext.grid.RowNumberer(),
			{
				header : '操    作',
				dataIndex : 'id',
				renderer : this.moduleActionRenderer({
					func : "toUpdatePur",
					desc : "查看单据"
				})
			}, {
				header : '单 据 号',
				dataIndex : 'codeOfBuyer'
			}, {
				header : '卖      方',
				dataIndex : 'partnerNameByBuyer'
			}, {
				header : '状      态',
				dataIndex : 'statusDes'
			}, {
				header : '金额(进价)',
				dataIndex : 'amount'
			}, {
				header : '当前处理人',
				dataIndex : 'currentor'
			}, {
				header : '创建人',
				dataIndex : 'creator'
			}, {
				header : '创建时间',
				dataIndex : 'gmtCreate'
			}, {
				header : '提交人',
				dataIndex : 'submitter'
			}, {
				header : '提交时间',
				dataIndex : 'gmtSubmit'
			}, {
				header : '发货人',
				dataIndex : 'deliveryer'
			}, {
				header : '发货时间',
				dataIndex : 'gmtDelivery'
			}, {
				header : '备    注',
				dataIndex : 'memoOfBuyer'
			} 
		]);
		
//		function createAddExecBtn(value, metadata, record, 
//			rowIndex, colIndex, store) {
//	
//			return '<div id="' + PUR_UPDATE_STRING + record.id + view_panel.main_win.versionCode + '">打开</div>';
//		}
		
//		&nbsp;&nbsp;&nbsp;<a id="' + PUR_DEL_STRING + record.id + '" href="#">删除</a>
//		<div id="' + record.id + '_showDetail' + '">查看明细</div>&nbsp;&nbsp;<a href="javascript:showPurDetail(\'' + record.id + '\',\'' + record.data.status + '\'' + '' + ');">查看明细</a></div>&nbsp;&nbsp;<div id="' + record.id + '_updatePur' + '"><a href="javascript:toUpdatePur(\'' + record.id + '\',\'' + record.data.status + '\');">修改订单</a>
		
		var show_pur_list_store = new Ext.data.Store( {
			proxy : new Ext.data.HttpProxy(
				{
					url : RES_PATH + '/purchase/getPurInfoByComplex.do',
					method : 'post'
				}
			),
	//		autoLoad : {params : {start : 0, limit : 2}},
			pruneModifiedRecords : true, 
			paramNames : {
				start : "start",
				limit : "limit"  
			},
			remoteSort:true,
			reader : new Ext.data.JsonReader(
				{
					totalProperty : 'totalProperty',
					root : 'root'
				}, 
				show_pur_list_record
			)
					
		} );
		this.show_pur_list_store = show_pur_list_store;
		
		var show_pur_list_grid = new Ext.grid.GridPanel( {
			title : '概要查询明细',
//			id : SHOW_PUR_LIST_GRID_ID,
			cm : show_pur_list_colName,
			store : show_pur_list_store,
			iconCls : 'icon-grid',
			loadMask : {
				msg : '数据加载中...'
			},
			viewConfig : {
//				forceFit:true
			},
//			width : '100%',
			height : 380,
	//		autoHeight : true,
			bbar: new Ext.PagingToolbar( {
	            pageSize : purOrSaleOrderPageSize,
	        	store : show_pur_list_store,
	       	 	displayInfo : true,
	        	displayMsg : '第 {0} - {1} 条  共 {2} 条',
	        	emptyMsg : "没有记录"
	        	
	        } )
		} );
		
		
		var show_pur_list_panel = new Ext.FormPanel( {
	//		labelAlign : 'right',
	//		frame : true,
			height : 400,
			autoWidth : true,
			autoScroll : true,
			items : [
	//					show_pur_list_form,
						show_pur_list_grid
					]
		} );
		
	//	show_details_panel = new Ext.Panel({
	//		id : PUR_DETAIL_PANEL_ID,
	//		labelAlign : 'right',
	//		frame : true,
	//		height : '100%',
	//		autoWidth : true,
	//		autoScroll : true,
	//		items : []
	//	});
		
		function showDetailsByMode() {
			var desktop = Uec3.App.getDesktop();   
			desktop.launchWindowByParam("showPurchaseDetailsWindowCreator",{});
//			openByUrl(SHOW_DETAIL_MODE_URL, '明细浏览');
		}
		
		function searchByCode() {
			var code = view_panel.getForm().findField('_codeOfBuyer').getValue();
			show_pur_list_store.baseParams = {codeOfBuyer : code};
			
			show_pur_list_store.load();
	//		show_pur_list_grid.getView().refresh();
		}
		
		function queryByComplex() {
			advanced_search_form_panel.getForm().reset();
			status_cmb.clearValue();
			openWind.show();
		}
		
		var view_panel = new Ext.FormPanel( {
	//	      title:'浏览订单',
//	          applyTo: 'showPurPanel',
		      items:[
		      	{
		          height:60,
		          layout:'hbox',
		          border:false,
		          layoutConfig: 
		             {     
		               padding:'5',
					   align:'middle' 
                  },
		          items : [
					 {				    
						xtype : 'label',
					    text : '浏览采购订单概要',
					    style : 'color:#000;font-size:26px;background:#fff'
					 }, {
		                xtype:'spacer',
                        flex:0.5
		             }, {
		             	xtype : 'button',
		             	text : '切换到明细浏览方式',
		             	margins:'0',
		             	handler : showDetailsByMode
		             }, {
	                     xtype : 'textfield',
	                     name : '_codeOfBuyer'
	                 }, {
		                  xtype : 'button',
		                  text : '查找单据号',                   
		                  margins : '0 10',
		                  handler : searchByCode
		             }, {
		                  xtype : 'button',
		                  text : '高级查找', 
		                  handler : queryByComplex
		             }, {
		                  xtype:'spacer',
		                  flex:1
		             }, {
		                  xtype : 'button',
		                  text : '新增采购订单',
		                  margins:'0 50',
		                  handler : toAddPurchase
		             }
		         ]
		      }, 
		      	show_pur_list_grid
		    ]
		} );
		
//		var ds_pur_status_select = new Ext.data.JsonStore({
//           url:Uec3.App.Constants.homeUrl+"/dictionary/findByVarGroup.do?group=order_status",
//           root: "",
//           autoLoad:true,
//           fields:[{name:'varIndex',type:'int'},{name:'varName',type:'string'}]
//        }); 
		
		var ds_pur_status_select = getDictionaryStore(RES_PATH, {
			group : 'order_status'
		});
		
		var status_cmb = getDictionaryComboBox(ds_pur_status_select, 'remote', 'status',
				'单据状态', 'status', 200);
				
//		ds_pur_status_select.load();
		
		var advanced_search_form_panel = new Ext.form.FormPanel({
		         labelSeparator : "：",
		         frame:true,
		         border:false,			    
		         items:[
		            {
		              xtype:'textfield',
				      width : 200,
		              fieldLabel:'单据号',
		              name:'codeOfBuyer'
		            }, status_cmb, {
		               xtype:'textfield',
				       width : 200,
		               fieldLabel:'供货商',
		               name:'partnerNameByBuyer' 
		            }, {
		               xtype:'datefield',
				       width : 200,
		               fieldLabel:'开始时间',
		               name:'gmtStart' ,
		               format:'Y-m-d'
		            }, {
		               xtype:'datefield',
		               width : 200,
		               fieldLabel:'结束时间',
		               name:'gmtEnd',
		               format:'Y-m-d'
		            }
		         ],
		      buttons:[
		        { 
		          text:'查找',
				  handler : searchResultByCondition
		        },{
		     	  text:'关闭',
		     	  handler : function(){	
		     	    openWind.hide();
		     	  }
		        }
		      ]
			
		});
		
		function toAddPurchase() {
			var desktop = Uec3.App.getDesktop();
			desktop.launchWindowByParam("addOutPurchaseOrderWindowCreator",{});
//			openByUrl(PUR_TO_ADD_NEW_URL, '新增订单');
		}
		
		/**
		 * 根据采购面板得到表单信息并转换成字符串
		 * 
		 * @return {}
		 */
		function getPurFormValues() {
			var form_values = advanced_search_form_panel.getForm().getValues();
	
			for (var j in form_values) {
				form_values[j] = castNoSelToNULL(form_values[j]);
			}
	
			form_values = Ext.util.JSON.encode(form_values);
	
			return form_values;
		}

		
		function searchResultByCondition() {
			var values = getPurFormValues();
			if(values) {
	    		show_pur_list_store.baseParams = {conditions : values};
			} else {
				show_pur_list_store.baseParams = {};
			}
			show_pur_list_store.load();
			openWind.hide();
		}
		
		var openWind = new Ext.Window({
			title:'高级查找',
		    layout:'fit',
	    	width:380,
	    	closeAction:'hide',
	    	height:330,
			resizable :true,
			shadow : true,
			modal :true,
	    	closable:true,
	    	bodyStyle:'padding:5 5 5 5',
	    	animCollapse:true,
			items:[advanced_search_form_panel]
	    });
	    
		
		function loadBtns() {
			Ext.Ajax.request( {
				url : INIT_BUTS_URL,
				success : function(data) {
					var vo = Ext.decode(data.responseText);
	//				removeButtonFieldSetFromPanel(show_pur_list_panel, PUR_BTN_FDSET_ID);
					createNewPurButtons(show_pur_list_panel, vo.btns, PUR_BTN_FDSET_ID);
				}
			});
		}
		
//		Ext.util.Observable.capture(show_pur_list_store, function(e){
//			if(e == 'load'){
//	//			var obj = {
//	//				add : false,
//	//				callback : function() {
//	//				}
//	//			};
//				addUpdateDetailEvent();
//			}
//		});
		
//		function addUpdateDetailEvent() {
//			var records = show_pur_list_store.getRange();
//	
//			Ext.each(records, function(record) {
//				var obj = Ext.get(PUR_UPDATE_STRING + record.id + view_panel.main_win.versionCode);
//				obj.on('click', function() {
//					toUpdatePur(this);	
//				}.bind(record));
//				
////				var _obj = Ext.get(PUR_DEL_STRING + record.id);
////				if(record.data.status == '2') {
////					_obj.hide();
////				} else {
////					_obj.on('click', function() {
////						toDelPur(this);
////					}.bind(record));
////				}
//			});	
//		}
		
		function init() {
			show_pur_list_store.load();
		}
		
		init();
		
		function addPurchase() {
			window.location.href = this.url;
		}
			
		function turnToModel() {
			Ext.Ajax.request( {
					url : this.url,
					success : function(data) {
						var vo = Ext.decode(data.responseText);
						removeButtonFieldSetFromPanel(show_pur_list_panel, PUR_BTN_FDSET_ID);
						createNewPurButtons(show_pur_list_panel, vo.btns, PUR_BTN_FDSET_ID);
					}
				});
		}
		
		function turnToOrderModel() {
		//	turnToModel.bind(this)();
		}
		
		function turnToDetailModel() {
		//	turnToModel.bind(this)();
			window.location.href = PUR_NEW_CREATE_URL;
		}
		
		return view_panel;
   }
} );
